/*!  http:/www.newkou.org | 不会飞的羊 */
 ! 
function(a) {
    a.fn.validation = function(b) {
        return this.each(function() {
            e = a.extend({},
            a.fn.validation.defaults, b),
            g(this)

        })

    },
    a.fn.validation.defaults = {
        validRules: [{
            name: "required",
            validate: function(b) {
                return a.trim(b) == ""

            },
            defaultMsg: "\u8bf7\u8f93\u5165\u5185\u5bb9\u3002"

        },
        {
            name: "number",
            validate: function(a) {
                return ! /^[0-9]\d*$/.test(a)

            },
            defaultMsg: "\u8bf7\u8f93\u5165\u6570\u5b57\u3002"

        },
        {
            name: "mail",
            validate: function(a) {
                return ! /^[a-zA-Z0-9]{1}([\._a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+){1,3}$/.test(a)

            },
            defaultMsg: "\u8bf7\u8f93\u5165\u90ae\u7bb1\u5730\u5740\u3002"

        },
        {
            name: "char",
            validate: function(a) {
                return ! /^[a-z\_\-A-Z]*$/.test(a)

            },
            defaultMsg: "\u8bf7\u8f93\u5165\u82f1\u6587\u5b57\u7b26\u3002"

        },
        {
            name: "chinese",
            validate: function(a) {
                return ! /^[\u4e00-\u9fff]$/.test(a)

            },
            defaultMsg: "\u8bf7\u8f93\u5165\u6c49\u5b57\u3002"

        },
        {name: 'mobile', validate: function(value) {return (!/^(13|15|18)[0-9]{9}$/.test(value));}, defaultMsg: '请输入正确手机号码。'},
		{name: 'passWord', validate: function(value) {return checkPwd($.trim(value));}, defaultMsg: '密码长度必须在6~16之间。'},
		{name: 'confirmPwd', validate: function(value) {return confirmPwd(value);}, defaultMsg: '两次密码不一致'},
		{name: 'dateYmd', validate: function(value) {return checkDate(value);}, defaultMsg: '请输入YYYY--MM--DD格式'},
		{name: 'idCard', validate: function(value) {return checkIdCard(value);}, defaultMsg: '请输入正确的身份证号码'},
		{name: 'username', validate: function(value) {return (!/\w{6,16}/.test(value)) ;}, defaultMsg: '只能由字母、数字、_(下划线)、-(减号)组成长度6-16'},
        ]

    };
    var b = !1,
    c = !1,
    d = !1,
    e = {},
    city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",
			23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",
			41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",
			52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",
			65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"},
	
     checkDate = function(value){
    	var r = value.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
    		if(r==null)return true; 
    	var d= new Date(r[1], r[3]-1, r[4]); 
    		return !(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
    },

    	
     confirmPwd = function(value){
    	var inputObj = $("input[type='password']");
    	var pwd1 = $.trim(inputObj.eq(0).val());
    	var pwd2 = $.trim(inputObj.eq(1).val());
    	if(pwd2!=''){
    		if(pwd1 == pwd2){	
    			return false;
    		}else{
    			return true;
    		}
    	}else{
    		return true;
    	}
    	
    },
    	
     checkPwd = function(value){
    	if(value.length >= 6 )
    	{		
    		if(/[a-zA-Z]+/.test(value) && /[0-9]+/.test(value) && /\W+\D+/.test(value)) {
    				return 1;
    		}else if(/[a-zA-Z]+/.test(value) || /[0-9]+/.test(value) || /\W+\D+/.test(value)) {
    			if(/[a-zA-Z]+/.test(value) && /[0-9]+/.test(value)) {
    				return 2;
    			}else if(/\[a-zA-Z]+/.test(value) && /\W+\D+/.test(value)) {
    				return 2;
    			}else if(/[0-9]+/.test(value) && /\W+\D+/.test(value)) {
    				return 2;
    			}else{
    				return 3;
    			}
    		}	
    	}else{
    		return -1;
    	}
    },

	
	 checkIdCard = function(value){ 
			var iSum=0,info="",birthday;
			if(!/^\d{17}(\d|x)$/i.test(value)){
				return true; 
			} 
			value=value.replace(/x$/i,"a"); 
			if(city[parseInt(value.substr(0,2))]==null){
				return true; 
			} 
			birthday=value.substr(6,4)+"-"+Number(value.substr(10,2))+"-"+Number(value.substr(12,2)); 
			var d=new Date(birthday.replace(/-/g,"/")) ;
			if(birthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate())){
				return true; 
			}
			for(var i = 17;i >= 0;i --){
				iSum += (Math.pow(2,i) % 11) * parseInt(value.charAt(17 - i),11) ;
			} 
			if(iSum%11!=1) {
				return true;
			} 
			return false;
		} ,
    f = function(b, d) {
        var f = a(b),
        g = !1,
        h = "";
        for (i = 0; i < d.length; i++) {
            var k = !0,
            l = d[i],
            m = f.attr(l + "-message") == undefined ? null: f.attr(l + "-message");
            l.substr(0, 1) == "!" && (k = !1, l = l.substr(1, l.length - 1));
            var n = e.validRules;
            for (j = 0; j < n.length; j++) {
                var o = n[j];
                if (l == o.name && o.validate.call(b, f.val()) == k) {
                    g = !0,
                    h = m == null ? o.defaultMsg: m;
                    break

                }

            }
            if (g) break

        }
        var p = f.parents(".controls"),
        q = f.parents(".control-group"),
        r = p.children(".help-block, .help-inline");
        if (g) {
            if (!q.hasClass("error")) {
                if (r.length > 0) {
                    var s = r.text();
                    p.data("help-message", s),
                    r.text(h)

                } else p.append('<span class="help-inline">' + h + "</span>");
                q.addClass("error")

            }

        } else if (c) {
            if (r.length > 0) {
                var s = p.data("help-message");
                s == undefined ? r.remove() : r.text(s)

            }
            q.attr("class", "control-group")

        } else if (r.length > 0) {
            var s = r.text();
            p.data("help-message", s)

        }
        return ! g

    },
    
    g = function(e) {
        a(e).submit(function() {
            if (b) return ! 1;
            b = !0;
            var e = !1;
            return a("input, textarea", this).each(function() {
                var b = a(this),
                c = b.attr("check-type") == undefined ? null: b.attr("check-type").split(" ");
                c != null && c.length > 0 && (f(this, c) || (d == 0 && (scrollTo(0, b[0].offsetTop - 50), d = !0), e = !0))

            }),
            d = !1,
            c = !0,
            e ? (b = !1, a("input, textarea").each(function() {
                var b = a(this),
                c = b.attr("check-type") == undefined ? null: b.attr("check-type").split(" ");
                c != null && c.length > 0 && (b.focus(function() {
                    var a = b.parents(".controls"),
                    c = b.parents(".control-group"),
                    d = a.children(".help-block, .help-inline");
                    if (d.length > 0) {
                        var e = a.data("help-message");
                        e == undefined ? d.remove() : d.text(e)

                    }
                    c.attr("class", "control-group")

                }), b.blur(function() {
                    f(this, c)

                }))

            }), !1) : !0

        })

    }

} (window.jQuery)